package net.paruo.google.gwt.study_meeting.user_control.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class UserAnchor extends Composite {

	private static UserAnchorUiBinder uiBinder = GWT
			.create(UserAnchorUiBinder.class);

	interface UserAnchorUiBinder extends UiBinder<Widget, UserAnchor> {
	}

	@UiField
	Anchor anchor;

	private final UserData data;

	UserAnchor(UserData data) {
		initWidget(uiBinder.createAndBindUi(this));

		this.data = data;
		anchor.setText(data.getName());
	}

	@UiHandler("anchor")
	void onClick(ClickEvent e) {
		UserDialogBox dialog = new UserDialogBox(data);
		dialog.center();
	}

	@UiHandler("anchor")
	void onMouseOver(MouseOverEvent e) {
		setStylePrimaryName("mouseOver");
	}

	@UiHandler("anchor")
	void onMouseOut(MouseOutEvent e) {
		setStylePrimaryName("mouseOut");
	}

	@UiHandler("anchor")
	void onMouseBlur(BlurEvent e) {
		setStylePrimaryName("mouseOut");
	}

}
